package com.conan.crud.controller;


import com.conan.crud.bean.Student;
import com.conan.crud.repository.StudentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RequestMapping("/student")
@RestController
public class StudentController {

    @Autowired
    private StudentRepository studentRepository;

    @RequestMapping(value = "{inform}",method = RequestMethod.GET)
    public String showStudent(@PathVariable("inform") String info){
        String[] strs = info.split(",");
        Student student = new Student();
        student.setId(Integer.parseInt(strs[0]));
        student.setName(strs[1]);
        student.setAge(Integer.parseInt(strs[2]));
        studentRepository.saveAndFlush(student);
        return student.toString();
    }

}
